package top100;

import java.util.HashMap;

/**
 * @author Godc
 * @description
 */
public class lengthOfLongestSubstring {
}
class LengthOfLongestSubstringSolution {
    /**
     * 滑动窗口,关键字:子串，
     * @param s
     * @return
     */
    public int lengthOfLongestSubstring(String s) {
        if(s.equals(""))
            return 0;
        HashMap<Character,Integer> map = new HashMap<>();
        int max = 0;
        int left = 0;
        for (int i = 0; i < s.length(); i++) {
            if(map.containsKey(s.charAt(i))){
                left =  Math.max(left,map.get(s.charAt(i)) + 1);
            }
            map.put(s.charAt(i),i);
            max = Math.max(max,i-left+1);
        }
        return max;
    }
}
